// src/types/public.ts

import type IFormItemConfig from "@/components/DynamicForm";
import { FormInstance, FormItemProps, UploadProps } from "antd";
import { ColumnType } from "antd/es/table";

// 表单控件类型定义
export type FormItemType =
  | "cascader"
  | "input-number"
  | "input"
  | "select"
  | "date"
  | "date-range"
  | "radio"
  | "checkbox"
  | "textarea"
  | "upload"
  | "password"
  | "custom"
  | "date-picker"
  | "editor"
  | "hidden"
  | "custom"
  | "window";
// 表单项配置接口
export interface IFormItemConfig {
  inputType?: FormItemType;
  key: string;
  title?: string;
  rules?: FormItemProps["rules"];
  size?: "small" | "middle" | "large";
  disabled?: boolean;
  placeholder?: string;
  options?: Array<{ label: string; value: any; disabled?: boolean }>;
  uploadProps?: UploadProps;
  style?: React.CSSProperties;
  className?: string;
  dependencies?: string[];
  render?: (value?: any, record?: any, key?: any) => React.ReactNode; // 自定义渲染函数
  multiple?: boolean;
  inputRender?: (value?: any) => React.ReactNode;
  initialValue?: any;
  autoSize?: boolean | { minRows: number; maxRows: number };
  rawvalue?: (value?: any) => Promise<any> | "string" | "number";
}

// 表单属性接口
export interface DynamicFormProps {
  formItems: IFormItemConfig[];
  form?: FormInstance;
  layout?: "horizontal" | "vertical" | "inline";
  onFinish?: (values: any) => void;
  onFinishFailed?: (errorInfo: any) => void;
  initialValues?: any[];
  submitButton?: React.ReactNode;
}

export interface DynamicFormRef {
  form: FormInstance;
}

// 修改后的 Fields 接口，确保与 IFormItemConfig 兼容
export interface Fields extends Omit<IFormItemConfig, "render"> {
  valueType?: "string" | "number";
  dataIndex?: string;
  width?: number | string;
  isEdit?: boolean;
  visible?: boolean;
  fixed?: "left" | "right" | "none";
  slotName?: any;
  tooltip?: string;
  title?: string;
  defaultValue?: any;
  render?: (_: any, record: any, key?: any) => React.ReactNode;

  // 移除从 ColumnType 继承的 title 类型冲突
  // 统一使用 IFormItemConfig 中的 title 类型 (string | undefined)
}

export interface TableAction<T> {
  add?: () => void;
  edit?: (record: T) => void;
  delete?: (ids: any[]) => void;
  detail?: (record: T) => void;
  migrate?: (record?: T) => void;
  custom?: (record: T) => void;
}
